﻿#if WINDOWS_UWP || NETFX_CORE
using System;
using System.Threading.Tasks;

using Windows.ApplicationModel.DataTransfer;

namespace Outcoder.LauncherModel.Launchers
{
	public class ShareLinkLauncher : LauncherBase, IShareLinkLauncher
	{
		public Uri LinkUri { get; set; }

		public string Description { get; set; }

		public string Title { get; set; }

		public override Task<bool> ShowAsync()
		{
			var dataTransferManager = DataTransferManager.GetForCurrentView();
			dataTransferManager.DataRequested += HandleDataRequested;

			DataTransferManager.ShowShareUI();

			return Task.FromResult(true);
		}

		void HandleDataRequested(DataTransferManager sender, DataRequestedEventArgs e)
		{
			var dataTransferManager = DataTransferManager.GetForCurrentView();
			dataTransferManager.DataRequested -= HandleDataRequested;

			e.Request.Data.Properties.Title = Title;
			e.Request.Data.Properties.Description = Description; // Optional 
			e.Request.Data.SetWebLink(LinkUri);
		}
	}
}
#endif